package com.yhq.oj.model.enums;

import org.apache.commons.lang3.ObjectUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 判题结果枚举
 *
 * @author yhq
 */
public enum JudgeInfoEnum {

    //    执行状态(0:待判题 1:判题中 2:成功 3: 解答出错 4:超出时间限制 5:超出空间限制 6:编译出错)
    SUCCESS("SUCCESS", 0),
    WAITING("WAITING", 1),
    COMPILE_ERROR("COMPILE_ERROR", 2),
    TIME_LIMITED_EXCEPTION("TIME_LIMITED_EXCEPTION", 3),
    OUT_OF_MEMORY("OUT_OF_MEMORY", 4),
    EXECUTE_ERROR("EXECUTE_ERROR", 5),
    WRONG_ANSWER("WRONG_ANSWER", 6),
    ACCEPTED("ACCEPTED", 7),
    RUNNING("RUNNING", 8);

    private final String status;

    private final Integer code;

    JudgeInfoEnum(String status, Integer code) {
        this.status = status;
        this.code = code;
    }

    /**
     * 获取值列表
     *
     * @return
     */
    public static List<Integer> getValues() {
        return Arrays.stream(values()).map(item -> item.code).collect(Collectors.toList());
    }

    /**
     * 根据 value 获取枚举
     *
     * @param value
     * @return
     */
    public static JudgeInfoEnum getEnumByValue(Integer value) {
        if (ObjectUtils.isEmpty(value)) {
            return null;
        }
        for (JudgeInfoEnum anEnum : JudgeInfoEnum.values()) {
            if (anEnum.code.equals(value)) {
                return anEnum;
            }
        }
        return null;
    }

    public Integer getCode() {
        return code;
    }

    public String getStatus() {
        return status;
    }
}
